home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / PredatorPrey / ProgramWindow.c < prev    next >
Text File  |  1996-06-22  |  8KB  |  327 lines

  1. /* ProgramWindow.c */    /*    C14 Calculator    */
  2. /* Created 940113 1:07 by AppMaker */
  3.  
  4. #ifndef __C14__
  5. #include    "PredatorPrey.h"
  6. #endif
  7. #include <Types.h>
  8. #include <Quickdraw.h>
  9. #include <Controls.h>
  10. #include <Dialogs.h>
  11. #include <Events.h>
  12. #include <Lists.h>
  13. #include <Menus.h>
  14. #include <Resources.h>
  15. #include <TextEdit.h>
  16. #include <ToolUtils.h>
  17. #include "ResourceDefs.h"
  18. #include "Globals.h"
  19. #include "Miscellany.h"
  20. #include "Scrolling.h"
  21. #include "WindowAids.h"
  22. #include "ProgWindowRsrcData.h"
  23. #include "ProgramWindow.h"
  24. #include "myLClikLoop.h"
  25.  
  26.  
  27. #define List1            1 
  28. #define List2            2 
  29. #define List3            3 
  30.  
  31. static void BuildList1    (void);
  32. static void BuildList2    (void);
  33. static void BuildList3    (void);
  34.  
  35. /*----------*/
  36. static void BuildList1    ()
  37. {
  38.     Rect            bounds;
  39.     short            i,rowInt;
  40.  
  41.     SetWFont (List1);
  42.     GetWRect (List1, &bounds);
  43.     cur->List1HandleProgramWindow = NewV1SList (bounds, qd.thePort);
  44.     rowInt = frog.END - 1;
  45.     if(rowInt >= 1)
  46.     {
  47.         for(i = 0;i <= rowInt;i++)
  48.         {
  49.             AddToList ("\po",   cur->List1HandleProgramWindow);
  50.         }
  51.     }
  52. /*    AddToList ("\pOne",   cur->List1HandleProgramWindow);*/
  53. /*    AddToList ("\pTwo",   cur->List1HandleProgramWindow);*/
  54. /*    AddToList ("\pThree", cur->List1HandleProgramWindow);*/
  55. /*    AddToList ("\pInfinity",  cur->List1HandleProgramWindow);*/
  56.     LDoDraw (true, cur->List1HandleProgramWindow);
  57.  
  58. } /*BuildList1*/
  59.  
  60. /*----------*/
  61. static void BuildList2    ()
  62. {
  63.     Rect            bounds;
  64.     short            i,rowInt;
  65.     short            dataLen;
  66.     Cell            theCell;
  67.     short            newRow;
  68.     
  69.     #define maxint    32767
  70.     
  71.     SetWFont (List2);
  72.     GetWRect (List2, &bounds);
  73.     cur->List2HandleProgramWindow = NewV1SList (bounds, qd.thePort);
  74.     rowInt = frog.END - 1;
  75.     if(rowInt >= 1)
  76.     {
  77.         dataLen = 12;
  78.         for(i = 0;i <= rowInt;i++)
  79.         {
  80.             newRow = LAddRow (1, maxint, cur->List2HandleProgramWindow);
  81.             theCell.v = i;
  82.             theCell.h = 0;
  83.             LSetCell(&frog.run[i].pStr[1],dataLen,theCell,cur->List2HandleProgramWindow);
  84.         }
  85.     }
  86.  
  87. /*    AddToList ("\pTwo",   cur->List2HandleProgramWindow);*/
  88. /*    AddToList ("\pThree", cur->List2HandleProgramWindow);*/
  89. /*    AddToList ("\pInfinity",  cur->List2HandleProgramWindow);*/
  90.     LDoDraw (true, cur->List2HandleProgramWindow);
  91.  
  92. } /*BuildList2*/
  93.  
  94. /*----------*/
  95. static void BuildList3    ()
  96. {
  97.     Rect            bounds;
  98.     short            i,rowInt;
  99.     short            dataLen;
  100.     Cell            theCell;
  101.     short            newRow;
  102.     
  103.     #define maxint    32767
  104.  
  105.     SetWFont (List3);            /*    in WindowAids.c    */
  106.     GetWRect (List3, &bounds);    /*    in WindowAids.c    */
  107.     cur->List3HandleProgramWindow = NewV1SList (bounds, qd.thePort);
  108.     //SetClikLoop((UniversalProcPtr) myLClikLoop,cur->List3HandleProgramWindow);
  109.     rowInt = frog.END - 1;
  110.     if(rowInt >= 1)
  111.     {
  112.         dataLen = 12;
  113.         for(i = 0;i <= rowInt;i++)
  114.         {
  115.             newRow = LAddRow (1, maxint, cur->List3HandleProgramWindow);
  116.             theCell.v = i;
  117.             theCell.h = 0;
  118.             LSetCell(&frog.run[i].pStr[1],dataLen,theCell,cur->List3HandleProgramWindow);
  119.         }
  120.     }
  121. /*    AddToList ("\pOne",   cur->List3HandleProgramWindow);*/
  122. /*    AddToList ("\pTwo",   cur->List3HandleProgramWindow);*/
  123. /*    AddToList ("\pThree", cur->List3HandleProgramWindow);*/
  124. /*    AddToList ("\pInfinity",  cur->List3HandleProgramWindow);*/
  125.     LDoDraw (true, cur->List3HandleProgramWindow);
  126.  
  127. } /*BuildList3*/
  128.  
  129. /*----------*/
  130. WindowPtr OpenProgramWindow    (Str255        fName,
  131.                              short        vRefNum,
  132.                              short        fRefNum)
  133. {
  134.     WindowPtr        newWindow;
  135.     WindowPtr        saveWindow;
  136.  
  137.     Rect            bounds;
  138.  
  139.     newWindow = GetWindow (ProgramWindowID);
  140.     if (fName [0] != 0) {
  141.         SetWTitle (newWindow, fName);
  142.     }
  143. /*    altCurWindow = curWindow;*/
  144. /*    SetAltInfo(altCurWindow);*/
  145.     SetPort (newWindow);
  146.     SetNewInfo (newWindow);
  147.     /*cur->map = altCur->map;*/
  148.     cur->vScroll = nil;
  149.     cur->hScroll = nil;
  150.     cur->fileNum    = fRefNum;
  151.     cur->volNum        = vRefNum;
  152.     cur->dirty        = false;
  153.     cur->filename    = NewString (fName);
  154.     cur->windowKind = WProgramWindow;
  155.     ((WindowPeek) curWindow)->windowKind = userKind + WProgramWindow;
  156.     cur->witlHandle = GetResource ('Witl', ProgramWindowID);
  157.     cur->wictHandle = GetResource ('Wict', ProgramWindowID);
  158.  
  159.     BuildList1 ();        /*    this    */
  160.     BuildList2 ();
  161.     BuildList3 ();
  162.     
  163.     cur->text = nil;
  164.     return(newWindow);
  165.  
  166. } /*OpenProgramWindow*/
  167.  
  168. /*----------*/
  169. void CloseProgramWindow    (void)
  170. {
  171.     WindowPtr    whichWindow;
  172.     
  173.     if ( ( whichWindow = FrontWindow() ) != gProgWindow)
  174.     
  175.     {
  176.         SelectWindow(gProgWindow);
  177.         SetInfo(gProgWindow);
  178.     }
  179.     LDispose (cur->List1HandleProgramWindow);
  180.     LDispose (cur->List2HandleProgramWindow);
  181.     LDispose (cur->List3HandleProgramWindow);
  182.     
  183.     DisposHandle ((Handle) cur->filename);
  184.     DiscardInfo (curWindow);
  185. } /*CloseProgramWindow*/
  186.  
  187. /*----------*/
  188. void ControlProgramWindow  (ControlHandle        whichControl,
  189.                          short                whichPart,
  190.                          Point                where)
  191. {
  192.     Rect            bounds;
  193.     short            deltaRows,deltaClms;
  194.  
  195.     if ((whichControl == (**(cur->List1HandleProgramWindow)).vScroll)
  196.     ||  (whichControl == (**(cur->List1HandleProgramWindow)).hScroll)) {
  197.         if (LClick (where, 0, cur->List1HandleProgramWindow)) {
  198.             /*double click in scroll bar*/
  199.         }
  200.     }
  201.     if ((whichControl == (**(cur->List2HandleProgramWindow)).vScroll)
  202.     ||  (whichControl == (**(cur->List2HandleProgramWindow)).hScroll)) {
  203.         if (LClick (where, 0, cur->List2HandleProgramWindow)) {
  204.             /*double click in scroll bar*/
  205.         }
  206.     }
  207.     if ((whichControl == (**(cur->List3HandleProgramWindow)).vScroll)
  208.     ||  (whichControl == (**(cur->List3HandleProgramWindow)).hScroll)) {
  209.         /*switch(whichPart)*/
  210. /*        {*/
  211. /*            case inUpButton:*/
  212. /*                deltaRows = 1;*/
  213. /*                break;*/
  214. /*            case inDownButton:*/
  215. /*                deltaRows = -1;*/
  216. /*                break;*/
  217. /*            case inPageUp:*/
  218. /*                deltaRows = 20;*/
  219. /*                break;*/
  220. /*            case inPageDown:*/
  221. /*                deltaRows = -20;*/
  222. /*                break;*/
  223. /*        }*/
  224. /*        while(gTheEvent.message != mouseUp)*/
  225. /*        {*/
  226. /*            LScroll( deltaClms, deltaRows, cur->List1HandleProgramWindow );*/
  227. /*            LScroll( deltaClms, deltaRows, cur->List2HandleProgramWindow );*/
  228. /*            LScroll( deltaClms, deltaRows, cur->List3HandleProgramWindow );*/
  229. /*        }*/
  230.         if (LClick (where, 0, cur->List3HandleProgramWindow)) {
  231.             /*double click in scroll bar*/
  232.         }
  233.     }
  234.     
  235. } /*ControlProgramWindow*/
  236.  
  237. /*----------*/
  238. void MouseInProgramWindow    (Point        where,
  239.                          short        modifiers)
  240. {
  241.     Rect            bounds;
  242.  
  243.     if (PtInRect (where, &(**(cur->List1HandleProgramWindow)).rView)) {
  244.         if (LClick (where, modifiers, cur->List1HandleProgramWindow)) {
  245.             /*double click*/
  246.         }
  247.         if (GetListChoice (&cur->List1ChoiceProgramWindow, cur->List1HandleProgramWindow)) {
  248.             /* something is selected */
  249.         }
  250.     }
  251.     if (PtInRect (where, &(**(cur->List2HandleProgramWindow)).rView)) {
  252.         if (LClick (where, modifiers, cur->List2HandleProgramWindow)) {
  253.             /*double click*/
  254.         }
  255.         if (GetListChoice (&cur->List2ChoiceProgramWindow, cur->List2HandleProgramWindow)) {
  256.             /* something is selected */
  257.         }
  258.     }
  259.     if (PtInRect (where, &(**(cur->List3HandleProgramWindow)).rView)) {
  260.         if (LClick (where, modifiers, cur->List3HandleProgramWindow)) {
  261.             /*double click*/
  262.         }
  263.         if (GetListChoice (&cur->List3ChoiceProgramWindow, cur->List3HandleProgramWindow)) {
  264.             /* something is selected */
  265.         }
  266.     }
  267.     
  268. } /*MouseInProgramWindow*/
  269.  
  270. /*----------*/
  271. void TypeInProgramWindow   (char        ch)
  272. {
  273.     if (cur->text == nil) {
  274.         SysBeep (1);
  275.     } else {
  276.         TEKey (ch, cur->text);
  277.         cur->dirty = true;
  278.     }
  279. } /*TypeInProgramWindow*/
  280.  
  281. /*----------*/
  282. void UpdateProgramWindow (void)
  283. {
  284.     Rect            bounds;
  285.  
  286.     SetWFont (List1);
  287.     LUpdate (qd.thePort->visRgn, cur->List1HandleProgramWindow);
  288.     bounds = (**(cur->List1HandleProgramWindow)).rView;
  289.     InsetRect (&bounds, -1, -1);
  290.     FrameRect (&bounds);
  291.     SetWFont (List2);
  292.     LUpdate (qd.thePort->visRgn, cur->List2HandleProgramWindow);
  293.     bounds = (**(cur->List2HandleProgramWindow)).rView;
  294.     InsetRect (&bounds, -1, -1);
  295.     FrameRect (&bounds);
  296.     SetWFont (List3);
  297.     LUpdate (qd.thePort->visRgn, cur->List3HandleProgramWindow);
  298.     bounds = (**(cur->List3HandleProgramWindow)).rView;
  299.     InsetRect (&bounds, -1, -1);
  300.     FrameRect (&bounds);
  301.     
  302. } /*UpdateProgramWindow*/
  303.  
  304. /*----------*/
  305. void ActivateProgramWindow    (Boolean    activate)
  306. {
  307.     LActivate (activate, cur->List1HandleProgramWindow);
  308.     LActivate (activate, cur->List2HandleProgramWindow);
  309.     LActivate (activate, cur->List3HandleProgramWindow);
  310.     
  311. } /*ActivateProgramWindow*/
  312.  
  313. /*----------*/
  314. void ResizeProgramWindow    (void)
  315. {
  316.     /* application-specific code to resize items in window */
  317. } /*ResizeProgramWindow*/
  318.  
  319. /*----------*/
  320. pascal void ScrollProgramWindow    (short        newValue,
  321.                                   short        oldValue)
  322. {
  323.     /* application-specific code to scroll window */
  324. } /*ScrollProgramWindow*/
  325.  
  326. /* ProgramWindow */
  327.